package admin

import (
	"exercise/application/yiran/app/libs"
	"exercise/application/yiran/app/request/adminRequest"
	"exercise/application/yiran/app/service/admin"
	"github.com/gin-gonic/gin"
)

type dbfController struct{}

// RecognizeDbf 校验省份文件
func (d *dbfController) RecognizeDbf(ctx *gin.Context) {
	request := new(adminRequest.RecognizeDbfRequest)
	err := libs.BindRequest(ctx, request)

	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	ret, err := admin.NewDbfService().RecognizeDbf(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, ret)
}

// CorrectionProvince 省份纠正
func (d *dbfController) CorrectionProvince(ctx *gin.Context) {
	request := new(adminRequest.CorrectionProvinceRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	err = admin.NewDbfService().CorrectionProvince(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "纠正成功")
}

// MovingProvinceClamp 文件夹移动
func (d *dbfController) MovingProvinceClamp(ctx *gin.Context) {
	request := new(adminRequest.MovingProvinceClampRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	err = admin.NewDbfService().MovingProvinceClamp(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "移动成功")
}

// ReadDbf 读取dbf中的数据
func (d *dbfController) ReadDbf(ctx *gin.Context) {
	request := new(adminRequest.ReadDbfRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	ret, err := admin.NewDbfService().ReadDbf(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, ret)
}

func NewDbfController() *dbfController {
	return &dbfController{}
}
